package com.itcam.cm.manager.task;

import com.itcam.cm.manager.mapper.OrderInfoMapper;
import com.itcam.cm.manager.service.OrderStatisticsService;
import com.itcam.cm.model.entity.order.OrderStatistics;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.util.Date;
import java.util.List;

// @Component
public class TestTask1 {

    @Autowired
    OrderInfoMapper orderInfoMapper;

    @Autowired
    OrderStatisticsService orderStatisticsService;

    @Scheduled(cron = "0/10 * * * * ?")
    public void t1() {
//        System.out.println("使用分组统计sql查询order_info");
//        DateTime now = DateTime.now();
//        String dateTime = now.minusDays(1).toString("YYYY-MM-dd");
//        System.out.println(dateTime);
        String dateTime = "2024-05-05";
        List<OrderStatistics> orderStatistics = orderInfoMapper.selectCountOrder(dateTime);
        System.out.println(orderStatistics);
        System.out.println("将分组查询结果插入order_statistics");
        orderStatisticsService.saveStatistics(orderStatistics);
    }

    public static void main(String[] args) {

    }
}
